<template>
  <div class="coupons">
    <Theme :theme="theme"></Theme>
    <div class="content">
      <div class="content_top">
        <div id="nav_l" :class="{ current: currIdx == 0 }" @click="show(0)">
          饮品/食品/配送劵
        </div>
        <div id="nav_r" :class="{ current: currIdx == 1 }" @click="show(1)">
          电商超品劵
        </div>
      </div>
      <div class="remind">
        <van-cell-group>
          <van-switch-cell
            v-model="checked"
            title="劵过期提醒"
            active-color="#6d86c4"
          />
        </van-cell-group>
        <ul class="content_down">
          <li class="newimg" ref="newImg">
            <img src="../../assets/lsc/vouchers.jpg" alt="" />
          </li>
          <li class="newli" v-for="coupon in coupons" :key="coupon.id">
            <h4>{{ coupon.title }}</h4>
            <p>
              {{ coupon.useful }}
              <span
                >￥<i>{{ coupon.price }}</i></span
              >
            </p>
            <p>使用规则 <button @click="skip">立即使用</button></p>
          </li>
        </ul>
      </div>
    </div>
    <div class="bottom"><img src="../../assets/lsc/bottom.jpg" alt="" /></div>
  </div>
</template>
<script>
import axios from "axios";
import Theme from "../../components/lsc/theme.vue";
export default {
  components: { Theme },
  created() {
    this.getlist();
  },
  methods: {
    show(index) {
      this.currIdx = index;
      this.getlist();
      console.log(this);
    },

    getlist() {
      axios({
        url: "http://localhost:3000/coupons",
        params: {
          type: this.types[this.currIdx],
        },
      }).then((res) => (this.coupons = res.data));
    },
    skip() {
      this.$router.push("/Caidan");
    },
  },

  data() {
    return {
      theme: "我的优惠劵",
      checked: false,
      currIdx: 0,
      coupons: [],
      types: ["new", "hot"],
    };
  },
};
</script>

<style scoped>
.coupons {
  width: 100%;
  min-height: 6.4rem;
  margin-top: 0.45rem;
  margin-bottom: 100px;
  background-color: #efeff4;
}
.content {
  margin-top: 0.3rem;
}
.van-cell__title,
.van-cell__value {
  font-size: 0.16rem;
}
.content_top {
  width: 90%;
  margin: 0.3rem auto;
  padding: 0.05rem;
  display: flex;
  border-radius: 0.3rem;
  justify-content: space-around;
  background-color: #4349a1;
}
.content_top .current {
  background-color: #ffffff;
  color: #000 !important;
}
#nav_l,
#nav_r {
  width: 1.46rem;
  height: 0.4rem;
  line-height: 0.4rem;
  border-radius: 0.3rem;
  text-align: center;
  color: #fff;
}
.remind {
  width: 90%;
  margin: 0.2rem auto;
  margin-bottom: 50px;
}
.content_down {
  width: 100%;
  padding-bottom: 1.2rem;
  overflow: hidden;
}
.content_down li {
  width: 100%;
  height: 1rem;
  margin: 0.1rem;
  border-radius: 0.07rem;
}
.content_down .newimg {
  margin-bottom: 0.2rem;
  border-radius: 0.07rem;
}
.content_down li img {
  width: 97%;
  border-radius: 0.07rem;
}
.bottom {
  width: 100%;
  height: 0.8rem;
  padding-top: 0.2rem;
  position: fixed;
  bottom: 0rem;
  background-color: #f5f5f5;
}
.bottom img {
  display: block;
  width: 90%;
  margin: 0 auto;
}
.content_down .newli {
  width: 88%;
  height: 1rem;
  padding: 0.15rem;
  background-color: #fff;
  border-radius: 0.12rem;
}
.newli h4 {
  color: #000;
  height: 0.4rem;
  line-height: 0.4rem;
  font-weight: normal;
}
.newli p {
  width: 100%;
  height: 0.3rem;
}
.newli p:nth-of-type(1) {
  font-size: 0.15rem;
  border-bottom: 0.01rem dotted #666;
  margin-bottom: 0.1rem;
  color: orange;
}
.newli p:nth-of-type(1) span {
  display: inline-block;
  float: right;
  margin-right: 0.08rem;
  font-size: 0.14rem;
  color: #6d86c4;
}
.newli p:nth-of-type(1) span i {
  font-style: normal;
  font-size: 0.2rem;
}
.newli p:nth-of-type(2) {
  font-size: 0.14rem;
  height: 0.33rem;
  line-height: 0.33rem;
}
.newli p button {
  width: 0.8rem;
  height: 0.3rem;
  background-color: #6d86c4;
  border: none;
  border-radius: 0.3rem;
  float: right;
  font-size: 0.15rem;
  color: #fff;
}
</style>